package book;

public class Book {

    //把书的属性都设置为private 实现封装
    private String name;
    private String author;
    private int price;
    private String type;

    //是否被借出，可以默认没有被借出
    private boolean isBorrowed;


    //成员变量初始化，提过带有参数的构造方法
    public Book(String name, String author, int price, String type) {
        this.name = name;
        this.author = author;
        this.price = price;
        this.type = type;
    }


    //为private属性提供getter和setter方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }


    public boolean isBorrowed() {
        return isBorrowed;
    }

    public void setBorrowed(boolean borrowed) {
        isBorrowed = borrowed;
    }


    //提供打印书的方法
    @Override
    public String toString() {
        return "Book{" +
                "name = '" + name + '\'' +
                ", author = '" + author + '\'' +
                ", price = " + price +
                ", type = '" + type + '\'' +
                ((isBorrowed == false) ? ", 未被借出" : ", 已被借出") +
                '}';
    }
}
